package com.zte.purchase.server.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zte.purchase.dao.IBrandDao;
import com.zte.purchase.model.BrandCondition;
import com.zte.purchase.model.BrandParam;
import com.zte.purchase.model.CBrand;
import com.zte.purchase.server.IBrandServer;
import com.zte.util.PageModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

@Service
public class BrandServer implements IBrandServer {

    @Autowired
    private IBrandDao brandDao;



    @Override
    public boolean addBrand(CBrand cBrand) {

        boolean isAdd = brandDao.addBrand(cBrand);
        return isAdd;

    }

    @Override
    public boolean updateBrand(CBrand cBrand) {

        boolean isUpdate = brandDao.updateBrand(cBrand);
        return isUpdate;

    }

    @Override
    public boolean updateBrandStatus(String BrandId, String brandStatus) {
        CBrand brand = new CBrand();
        brand.setBrandId(BrandId);
        brand.setBrandStatus(brandStatus);

        boolean isStatus = brandDao.updateBrand(brand);

        return isStatus;
    }

    @Override
    public CBrand findOneBrand(String brandId) {

        CBrand brand = brandDao.findOneBrand(brandId);

        return brand;
    }

    @Override
    public PageModel<CBrand> queryBrandPage(PageModel<CBrand> pageModel, BrandCondition conn) {
        int pageNum = pageModel.getPageNum()<=1?1:pageModel.getPageNum();
        int pageSize = pageModel.getPageSize() <= 0 ? 5 : pageModel.getPageSize();
        PageHelper.startPage(pageNum,pageSize);

        List<CBrand> cBrands = brandDao.queryBrandByCondition(conn);
        PageInfo<CBrand> info = new PageInfo<>(cBrands);
        return PageModel.getPageModel(pageModel,info);
    }

    @Override
    public List<BrandParam> queryBrandNameList() {
        List<BrandParam> names = brandDao.queryBrandNameList();

        return names;
    }
}
